
var PhoneModal, EmailModel
showPhoneModal = function () {
    PhoneModal = new bootstrap.Modal(document.getElementById('phoneModal'), {
        //点击背景不关闭
        backdrop: "static",
        //触发键盘esc事件时不关闭
    })
    PhoneModal.show()
}

showEmailModal = function () {
    EmailModel = new bootstrap.Modal(document.getElementById('emailModal'), {
        //点击背景不关闭
        backdrop: "static",
        //触发键盘esc事件时不关闭
    })
    EmailModel.show()
}
bindPhone = function () {
    let phone = document.getElementById('phone').value;
    if (phone === '') {
        Qmsg.error('手机号不能为空')
        return;
    }
    if (!isPhoneNumber(phone)) {
        Qmsg.error('手机号格式错误！')
        return;
    }
    axios({
        url: "/api/bind/phone",
        method: 'post',
        headers: {'Authorization': getToken()},
        params: {
            phone: phone
        }
    })
        .then(function (response) {
            if (response.data.code === 200) {
                Qmsg.success("绑定成功")
                window.location.reload()
            } else {
                Qmsg.error(response.data.msg)
            }
        }).catch(function (error) {
        console.log(error);
        Qmsg.error("未知错误")
    });
}
bindEmail = function () {
    let email = document.getElementById('email').value;
    if (email === '') {
        Qmsg.error('邮箱不能为空')
        return;
    }
    if (!isEmail(email)) {
        Qmsg.error('邮箱格式错误！')
        return;
    }

    axios({
        url: "/api/bind/email",
        method: 'post',
        headers: {'Authorization': getToken()},
        params: {
            email: email
        }
    })
        .then(function (response) {
            if (response.data.code === 200) {
                Qmsg.success("绑定成功")
                //清楚token
                window.location.reload()
            } else {
                Qmsg.error(response.data.msg)
            }
        }).catch(function (error) {
        console.log(error);
        Qmsg.error("未知错误")
    });
}
changePassword = function () {
    let password = document.getElementById("password").value;
    let rePassword = document.getElementById("rePassword").value;
    if (password === '') {
        Qmsg.error("请输入密码！")
    } else if (password.length < 8) {
        Qmsg.error("密码长度不能小于8！")
    } else if (rePassword !== password) {
        Qmsg.error("两次密码不一致")
    } else {
        axios({
            url: '/api/change/password',
            method: 'post',
            headers: {'Authorization': getToken()},
            params: {newPassword: password}
        }).then(function (response) {
            if (response.data.code === 200) {
                Qmsg.success("修改成功")
                //清楚token
            } else {
                Qmsg.error(response.data.msg)
            }
        }).catch(function (error) {
            console.log(error);
            Qmsg.error("未知错误")
        });
    }
}
